{include file="my/header"}



<div class="container-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <!-- 表格数据查询块 -->
            <div class="table-query">
                <form class="layui-form layui-inline" action="">
                    <div class="layui-inline">
                        <label class="layui-form-label">搜索ID：</label>
                        <div class="layui-inline">
                            <input class="layui-input J-query-params" name="id" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">考试任务：</label>
                        <div class="layui-inline">
                            <input class="layui-input J-query-params" name="name" autocomplete="off">
                        </div>
                    </div>

                    <div class="layui-inline">
                        <label class="layui-form-label">学期：</label>
                        <div class="layui-inline">
                            <input class="layui-input J-query-params" name="term" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">发布时间：</label>
                        <div class="layui-inline">
                            <input type="text" class="layui-input J-query-params J-date" name="create_time" placeholder="yyyy-MM-dd">
                        </div>
                    </div>

                </form>
                <button class="layui-btn J-search" data-type="reload">搜索</button>
                <button class="layui-btn J-reload">重置</button>
            </div>
            <!-- 表格 -->
            <table class="layui-hide" id="testTable" lay-filter="test"></table>
            <!-- 表格工具 -->
            <script type="text/html" id="toolbarDemo">
                <div class="layui-btn-container">
                    <button class="layui-btn layui-btn-sm" lay-event="add">添加</button>
                    <button class="layui-btn layui-btn-sm" lay-event="batchdel">批量删除</button>
                </div>
            </script>
            <script type="text/html" id="barDemo">
                <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
                <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
            </script>
          
        </div>
    </div>
    <script>
        $(function () {
            initTable();
            initClass('tasklist');
            layuiDate(".J-date")
        })

        function initTable() {
            var table;
            // 请求路径
            var requireUrl = {
                add: "{:url('test/taskadd')}",
                edit: "{:url('test/taskedit')}",
                remove: "{:url('test/taskremove')}",
                list: "{:url('test/gettasklist')}"
            }

            layui.use('table', function () {
                table = layui.table;
                table.render({
                    elem: '#testTable'
                    , url: requireUrl.list
                    , toolbar: '#toolbarDemo'
                    , title: '考试任务'
                    , totalRow: false
                    , cols: [[
                        { type: 'checkbox', fixed: 'left' }
                        , { field: 'id', title: '序号', }
                        , { field: 'name', title: '考试任务', }
                        , { field: 'term', title: '学期', }
                        , { field: 'create_time', title: '发布时间', }
                        , { fixed: 'right', title: '操作', toolbar: '#barDemo', width: 120 }
                    ]]
                    , id: 'testReload'
                    , page: true
                    , parseData: function (res) {
                        return {
                            "code": 0,
                            "msg": "",
                            "count": res.length,
                            "data": res
                        };
                    }
                });

                //工具栏事件
                table.on('toolbar(test)', function (obj) {
                    var checkStatus = table.checkStatus(obj.config.id);
                    switch (obj.event) {
                        case 'add':
                            tableAdd({
                                addUrl: requireUrl.add,
                                layerTemp: layerTemp,
                                title: '发布考试任务'
                            });
                            break;
                        case 'batchdel':
                            tableBatchDel(checkStatus, requireUrl.remove);
                            break;
                    };
                });

                //监听行工具事件
                table.on('tool(test)', function (obj) {
                    var data = obj.data;
                    console.log(data.id)
                    if (obj.event === 'del') {
                        layerConfirm(requireUrl.remove, {
                            id: data.id
                        })
                    } else if (obj.event === 'edit') {
                        layerOpenInit('考试任务编辑', layerTemp, function (index) {
                            var data = $("form").serialize();
                            ajaxRequest("post", requireUrl.edit, data, function (data) {
                                data.code == 1 ? successTrip(data) : errorAlert(false, data.msg);
                            })
                        }, function () {
                            ajaxRequest("get", requireUrl.edit, {
                                id: data.id
                            }, function (res) {
                                $("#id").val(res.data.id);
                                $("#name").val(res.data.name);
                                $("#term").val(res.data.term);
                            })
                        })
                    }
                });
            })

            // 搜索重置操作
            var active = {
                reload: function () {
                    var queryParams = serializeObject($("form"));
                    console.log(queryParams);
                    //执行重载
                    table.reload('testReload', {
                        page: {
                            curr: 1 //重新从第 1 页开始
                        }
                        , where: queryParams
                    }, 'data');
                }
            };
            $('.J-search').on('click', function () {
                var type = $(this).data('type');
                active[type] ? active[type].call(this) : '';
            });
            $('.J-reload').on('click', function () {
                $('.J-query-params').val('');
                active.reload ? active.reload.call(this) : '';
            });
        }

        var layerTemp = `
                  <div class="margin-top30">
                        <form class="layui-form  layui-fluid J-add-form">
                          <input type="hidden" class="form-control" id="id" name="id" value="" placeholder="请输入内容">
                          <input type="hidden" class="form-control" id="schoolid" name="schoolid" value="985" placeholder="请输入内容">
                          <div class="layui-form-item">
                            <label class="layui-form-label">考试任务</label>
                            <div class="layui-input-block">
                              <input type="text" lay-verify="required" required lay-reqtext="必填" autocomplete="off" class="layui-input" name="name" id="name" placeholder="请输入内容">
                            </div>
                          </div>
                          <div class="layui-form-item">
                            <label class="layui-form-label form-require">学期</label>
                            <div class="layui-input-block">
                              <input type="text" class="layui-input" name="term" id="term" placeholder="请输入内容">
                            </div>
                          </div>
                          <div class="layui-form-item">
                            <label for="inputEmail3" class="col-sm-2 control-label"></label>
                            <div class="col-sm-10">
                              <input type="hidden" class="form-control" id="uid" name="uid" value="3" placeholder="Email">
                            </div>
                          </div>
                        </form>
                  </div>`
    </script>

    {include file="my/footer"}